
package net.vinote.smart.platform.base;

import java.util.Hashtable;
import java.util.Map;

/**
 * 对系统级别的SRE属性进行维护
 * 
 * @author 郑俊伟
 * @version 1.0
 * @since JDK1.6
 */
public class SysPlatformModify<T> implements PlatformModify<T>
{
	/** 重写put() putAll()的实现,时存入的键为小写 */
	private Hashtable<String, T> configs = new Hashtable<String, T>()
	{
		private static final long serialVersionUID = 8157872564126595724L;

		@Override
		public synchronized T put(String key, T value)
		{
			return super.put(key.toLowerCase(), value);
		}

		@Override
		public synchronized void putAll(Map<? extends String, ? extends T> t)
		{
			for (Map.Entry<? extends String, ? extends T> e : t.entrySet())
				put(e.getKey().toLowerCase(), e.getValue());
		}

		@Override
		public synchronized T get(Object key)
		{
			if (key instanceof String)
			{
				return super.get(key.toString().toLowerCase());
			}
			else
			{
				return super.get(key);
			}
		}

	};

	@Override
	public Map<String, T> getAttributes()
	{
		return configs;
	}

	@Override
	public T getAttribute(String key)
	{
		return configs.get(key);
	}

	@Override
	public void put(String key, T t)
	{
		configs.put(key, t);
	}
}
